package com.ruoyi.web.controller.market.form;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.db.domain.FormInfoPushRecord;
import com.ruoyi.form.service.IFormInfoPushRecordService;
import com.ruoyi.form.service.IFormInfoService;
import com.ruoyi.market.enums.SpecialEnum;
import com.ruoyi.web.wapper.FormInfoPushRecordWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * api手动推送记录Controller
 * 
 * @author ruoyi
 * @date 2023-02-27
 */
@Controller
@RequestMapping("/form/record")
public class FormInfoPushRecordController extends BaseController
{
    private String prefix = "form/record";

    @Autowired
    private IFormInfoPushRecordService formInfoPushRecordService;

    @Autowired
    private IFormInfoService formInfoService;

    @RequiresPermissions("form:record:view")
    @GetMapping()
    public String record(ModelMap modelMap)
    {

        List<Map<String, String>> channelInfoList = formInfoService.selectChannelInfoListMap();
        modelMap.put("channelInfoList", channelInfoList);

        return prefix + "/record";
    }

    /**
     * 查询api手动推送记录列表
     */
    @RequiresPermissions("form:record:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FormInfoPushRecord formInfoPushRecord)
    {
        startPage();
        List<Map<String, Object>> mapList = formInfoPushRecordService.selectFormInfoPushRecordListMap(formInfoPushRecord);
        mapList = new FormInfoPushRecordWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出api手动推送记录列表
     */
    @RequiresPermissions("form:record:export")
    @Log(title = "api手动推送记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FormInfoPushRecord formInfoPushRecord)
    {
        List<FormInfoPushRecord> list = formInfoPushRecordService.selectFormInfoPushRecordList(formInfoPushRecord);
        ExcelUtil<FormInfoPushRecord> util = new ExcelUtil<FormInfoPushRecord>(FormInfoPushRecord.class);
        return util.exportExcel(list, "api手动推送记录数据");
    }

    /**
     * 新增api手动推送记录
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        List<Map<String, String>> channelInfoList = formInfoService.selectChannelInfoListMap();
        modelMap.put("channelInfoList", channelInfoList);

        List<Map<String, String>> dataMapList = SpecialEnum.ZhimaScore.getDataMap();
        modelMap.put("dataMapList", dataMapList);

        return prefix + "/add";
    }

    /**
     * 新增保存api手动推送记录
     */
    @RequiresPermissions("form:record:add")
    @Log(title = "api手动推送记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FormInfoPushRecord formInfoPushRecord)
    {
        return toAjax(formInfoPushRecordService.insertFormInfoPushRecord(formInfoPushRecord));
    }

    /**
     * 修改api手动推送记录
     */
    @RequiresPermissions("form:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FormInfoPushRecord formInfoPushRecord = formInfoPushRecordService.selectFormInfoPushRecordById(id);
        mmap.put("formInfoPushRecord", formInfoPushRecord);

        List<Map<String, Object>> dataMapList = SpecialEnum.ZhimaScore.getDataMapListCheckd(formInfoPushRecord.getFilterZhima());
        mmap.put("dataMapList", dataMapList);

        return prefix + "/edit";
    }

    /**
     * 修改保存api手动推送记录
     */
    @RequiresPermissions("form:record:edit")
    @Log(title = "api手动推送记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FormInfoPushRecord formInfoPushRecord)
    {
        return toAjax(formInfoPushRecordService.updateFormInfoPushRecord(formInfoPushRecord));
    }

    /**
     * 删除api手动推送记录
     */
    @RequiresPermissions("form:record:remove")
    @Log(title = "api手动推送记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(formInfoPushRecordService.deleteFormInfoPushRecordByIds(ids));
    }
}
